package com.jzy.shardingjdbc.web;

import com.jzy.shardingjdbc.entity.GoodInfo;
import com.jzy.shardingjdbc.entity.User;
import com.jzy.shardingjdbc.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jinzhiyuan
 * @Description: 接口层
 * @date 2020-4-28 17:37
 */
@RestController
public class UserController {

    Logger logger= LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    @GetMapping("/users")
    public Object list() {
        return userService.list();
    }

    @GetMapping("/add")
    public Object add() {

        for(int i=100;i<150;i++) {
            User user = new User();
            user.setId(i);
            user.setUsername("forezp"+(i));
            user.setPassword("1233edwd");
            long resutl=   userService.addUser(user);
            logger.info("insert:"+user.toString()+" result:"+resutl);
        }
        return "ok";
    }

    @GetMapping("/addGood")
    public Object addGood() {

        for(int i=100;i<1500;i++) {
            GoodInfo goodInfo = new GoodInfo();
            goodInfo.setGood_id(i);
            goodInfo.setGood_name("手机" + i);
            goodInfo.setGood_description("iphone 11 " + i + "描述");
            goodInfo.setGood_price(String.valueOf(i) + "元");
            long resutl=   userService.addGoods(goodInfo);
            logger.info("insert:"+ goodInfo.toString() +" result:" + resutl);
        }
        return "ok";
    }

    @GetMapping("/get/good/list")
    public Object getGoodList() {
        return userService.getGoodList();
    }
}
